<template>
  <div class="form-wapper">
    <van-nav-bar
      :title="$route.meta.title"
      left-arrow
      :border="false"
      @click-left="clickLeft"
      @click-right="clickRight"
    >
      <template #right>
        <van-icon name="success" size="24" />
        <span
          style="
            margin-left: 2px;
            color: #fff;
            margin-top: 3px;
            font-size: 20px;
          "
          >保存</span
        >
      </template>
    </van-nav-bar>
    <div class="sampleItem">
      <van-form @submit="onSubmit" ref="subForm" scroll-to-error>
        <van-row type="flex">
          <van-col span="12" class="readonly">
            <van-field
              v-model="MaterialName"
              name="MaterialName"
              label="产品名称"
              input-align="center"
              readonly
            >
            </van-field>
          </van-col>
          <van-col span="12" class="readonly">
            <van-field
              v-model="MaterialCode"
              name="MaterialCode"
              label="产品代码"
              input-align="center"
              readonly
            >
            </van-field>
          </van-col>
          <van-col span="12" class="readonly">
            <van-field
              v-model="OriginName"
              name="OriginName"
              label="生产车间"
              input-align="center"
              readonly
            >
            </van-field>
          </van-col>
          <van-col span="12" class="readonly">
            <van-field
              v-model="MaterialTypeName"
              name="MaterialTypeName"
              label="产品类别"
              input-align="center"
              readonly
            >
            </van-field>
          </van-col>
          <van-col span="12" class="readonly">
            <van-field
              v-model="ProductSpecification"
              name="ProductSpecification"
              label="规格"
              input-align="center"
              readonly
            >
            </van-field>
          </van-col>
          <van-col span="12" class="readonly">
            <van-field
              v-model="PackStandard"
              name="PackStandard"
              label="包装规格"
              input-align="center"
              readonly
            >
            </van-field>
          </van-col>
          <van-col span="12" class="readonly">
            <van-field
              v-model="BatchID"
              name="BatchID"
              label="批号"
              input-align="center"
              readonly
            >
            </van-field>
          </van-col>
          <van-col span="12" class="readonly">
            <van-field
              v-model="ProductDate"
              name="ProductDate"
              label="生产日期"
              input-align="center"
              readonly
            >
            </van-field>
          </van-col>
          <van-col span="12" class="readonly">
            <van-field
              v-model="EffectDate"
              name="EffectDate"
              label="有效期至"
              input-align="center"
              readonly
            >
            </van-field>
          </van-col>
          <van-col span="12" class="readonly">
            <van-field
              v-model="TotalTxt"
              name="TotalTxt"
              label="总数量"
              input-align="center"
              readonly
            >
            </van-field>
          </van-col>
          <van-col span="12" class="readonly">
            <van-field
              v-model="TestID"
              name="TestID"
              label="请验单编号"
              input-align="center"
              readonly
            >
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="TotalMixingDate"
              name="TotalMixingDate"
              label="总混日期"
              input-align="center"
              clickable
            >
              <template #input>
                <picker-date v-model="TotalMixingDate" :timeType="'date'" />
              </template>
            </van-field>
          </van-col>
          <van-col span="8" style="width: 31%">
            <van-field
              v-model="FirstSample"
              name="FirstSample"
              label="取样次数"
              input-align="center"
            >
              <template #input>
                <fixed-select
                  v-model="FirstSample"
                  :dataList="FirstSampleArr"
                />
              </template>
            </van-field>
          </van-col>
          <van-col
            span="4"
            style="width: 19%"
            :class="{ readonly: isReadOnly }"
          >
            <van-field
              type="number"
              v-model="SampleNumber"
              name="SampleNumber"
              input-align="center"
              :readonly="isReadOnly"
            ></van-field>
          </van-col>
          <van-col span="12">
            <van-field
              type="number"
              v-model="PieceTotal"
              name="PieceTotal"
              label="总件数"
              input-align="center"
            >
            </van-field>
          </van-col>
          <van-col span="12" class="readonly">
            <van-field
              v-model="SamplePieceStaging"
              name="SamplePieceStaging"
              label="计算公式"
              input-align="center"
              readonly
            >
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="SamplePieceValue"
              name="SamplePieceValue"
              label="取样件数"
              input-align="center"
            >
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="SampleRealPiece"
              name="SampleRealPiece"
              label="实际取样件数"
              input-align="center"
            >
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="SampleLocation"
              name="SampleLocation"
              label="取样地点"
              input-align="center"
            >
              <template #input>
                <select-one
                  v-model="SampleLocation"
                  :dataList="SampleLocationArr"
                />
              </template>
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="SampleTool"
              name="SampleTool"
              label="取样工具"
              input-align="center"
            >
              <template #input>
                <mult-select
                  v-model="SampleTool"
                  :dataList="SampleToolArr"
                  @chooseValue="updataSampleTool"
                />
              </template>
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="DisinfectDisinfect"
              name="DisinfectDisinfect"
              label="工具是否消毒"
              input-align="center"
            >
              <template #input>
                <fixed-select
                  v-model="DisinfectDisinfect"
                  :dataList="DisinfectDisinfectArr"
                />
              </template>
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="SampleContainer"
              name="SampleContainer"
              label="盛样容器"
              input-align="center"
            >
              <template #input>
                <mult-select
                  v-model="SampleContainer"
                  :dataList="SampleContainerArr"
                  @chooseValue="updataSampleContainer"
                />
              </template>
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="ContainerDisinfect"
              name="ContainerDisinfect"
              label="容器是否消毒"
              input-align="center"
            >
              <template #input>
                <fixed-select
                  v-model="ContainerDisinfect"
                  :dataList="ContainerDisinfectArr"
                />
              </template>
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="SampleProcess1"
              name="SampleProcess1"
              label="取样过程1"
              input-align="center"
            >
              <template #input>
                <select-one
                  v-model="SampleProcess1"
                  :dataList="SampleProcess1Arr"
                />
              </template>
            </van-field>
          </van-col>
          <van-col span="8" style="width: 31%" v-if="showsample1">
            <van-field
              v-model="box"
              name="box"
              label="取样数量1"
              input-align="center"
            >
            </van-field>
          </van-col>
          <van-col
            span="4"
            style="width: 19%"
            class="readonly"
            v-if="showsample1"
          >
            <van-field
              v-model="boxUnit"
              name="boxUnit"
              readonly
              input-align="center"
            >
            </van-field>
          </van-col>
          <van-col span="12" v-if="showsample1">
            <van-field
              v-model="boxTime"
              name="boxTime"
              label="取样日期1"
              input-align="center"
              clickable
            >
              <template #input>
                <picker-date v-model="boxTime" :timeType="'datetime'" />
              </template>
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="SampleProcess2"
              name="SampleProcess2"
              label="取样过程2"
              input-align="center"
            >
              <template #input>
                <select-one
                  v-model="SampleProcess2"
                  :dataList="SampleProcess2Arr"
                />
              </template>
            </van-field>
          </van-col>
          <van-col span="8" style="width: 31%" v-if="showsample2">
            <van-field
              v-model="ProcessSingleCount"
              name="ProcessSingleCount"
              label="单件取样量约"
              input-align="center"
            >
            </van-field>
          </van-col>
          <van-col span="4" style="width: 19%" v-if="showsample2">
            <van-field
              v-model="ProcessSingleCountUnit"
              name="ProcessSingleCountUnit"
              readonly
              input-align="center"
            >
              <template #input>
                <fixed-select-one
                  v-model="ProcessSingleCountUnit"
                  :dataList="ProcessSingleCountUnitArr"
                />
              </template>
            </van-field>
          </van-col>
          <van-col span="8" style="width: 31%" v-if="showsample2">
            <van-field
              v-model="ProcessSingleStandard"
              name="ProcessSingleStandard"
              label="取样件数"
              input-align="center"
            >
            </van-field>
          </van-col>
          <van-col
            span="4"
            style="width: 19%"
            class="readonly"
            v-if="showsample2"
          >
            <van-field
              v-model="ProcessSingleStandardUnit"
              name="ProcessSingleStandardUnit"
              readonly
              input-align="center"
            >
            </van-field>
          </van-col>
          <van-col span="8" style="width: 31%" v-if="showsample2">
            <van-field
              v-model="ProcessSumCount"
              name="ProcessSumCount"
              label="总取样量约"
              input-align="center"
            >
            </van-field>
          </van-col>
          <van-col span="4" style="width: 19%" v-if="showsample2">
            <van-field
              v-model="ProcessSumCountUnit"
              name="ProcessSumCountUnit"
              readonly
              input-align="center"
            >
              <template #input>
                <fixed-select-one
                  v-model="ProcessSumCountUnit"
                  :dataList="ProcessSumCountUnitArr"
                />
              </template>
            </van-field>
          </van-col>
          <van-col span="12" v-if="showsample2">
            <van-field
              v-model="CleanUser"
              name="CleanUser"
              label="清洁人"
              input-align="center"
            >
            </van-field>
          </van-col>
          <van-col span="7" style="width: 31%" v-if="showsample2">
            <van-field
              v-model="SampleStart"
              name="SampleStart"
              label="取样时间"
              input-align="center"
              clickable
            >
              <template #input>
                <picker-date v-model="SampleStart" :timeType="'datetime'" />
              </template>
            </van-field>
          </van-col>
          <van-col span="5" style="width: 19%" v-if="showsample2">
            <van-field
              v-model="SampleEnd"
              name="SampleEnd"
              input-align="center"
              clickable
            >
              <template #input>
                <picker-date v-model="SampleEnd" :timeType="'datetime'" />
              </template>
            </van-field>
          </van-col>
          <van-col span="7" style="width: 31%" v-if="showsample2">
            <van-field
              v-model="CleanStart"
              name="CleanStart"
              label="清洁时间"
              input-align="center"
              clickable
            >
              <template #input>
                <picker-date v-model="CleanStart" :timeType="'datetime'" />
              </template>
            </van-field>
          </van-col>
          <van-col span="5" style="width: 19%" v-if="showsample2">
            <van-field
              v-model="CleanEnd"
              name="CleanEnd"
              input-align="center"
              clickable
            >
              <template #input>
                <picker-date v-model="CleanEnd" :timeType="'datetime'" />
              </template>
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="Submission"
              name="Submission"
              label="总送检样"
              input-align="center"
            >
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="Physicochemical"
              name="Physicochemical"
              label="理化用"
              input-align="center"
            >
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="Microorganism"
              name="Microorganism"
              label="微生物用"
              input-align="center"
            >
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="RetentionSample"
              name="RetentionSample"
              label="留样用"
              input-align="center"
            >
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="StorageConditions"
              name="StorageConditions"
              label="样品存储条件"
              input-align="center"
            >
              <template #input>
                <select-one
                  v-model="StorageConditions"
                  :dataList="StorageConditionsArr"
                />
              </template>
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="SamplecCode"
              name="SamplecCode"
              label="取样编号"
              input-align="center"
            >
            </van-field>
          </van-col>
          <van-col span="12">
            <van-field
              v-model="sampleUserId"
              name="sampleUserId"
              label="取样人"
              input-align="center"
            >
              <template #input>
                <mult-select
                  v-model="sampleUserId"
                  :dataList="sampleUserIdArr"
                  @chooseValue="updataSampleUserId"
                />
              </template>
            </van-field>
          </van-col>
          <van-col span="24">
            <van-field
              v-model="Remark"
              name="Remark"
              label="备注"
              input-align="center"
            >
            </van-field>
          </van-col>
        </van-row>
      </van-form>
    </div>
  </div>
</template>

<script>
import {
  Form,
  Field,
  NavBar,
  Button,
  Popup,
  Toast,
  Col,
  Row,
  Checkbox,
  CheckboxGroup,
  TreeSelect,
  Notify,
  Icon,
} from "vant";
import PickerUnit from "@/components/PickerUnit";
import PickerDate from "@/components/PickerDate";
import PickerDateOne from "@/components/PickerDateOne";
import FixedSelect from "@/components/FixedSelect";
import SelectOne from "@/components/SelectOne";
import FixedSelectOne from "@/components/FixedSelectOne";
import MultSelect from "@/components/MultSelect";

import { saveSampleData, GetSampleRecordHeadById } from "@/api/check";
import { getDictionaryTree, GetUserList } from "@/api/base";

export default {
  components: {
    [Form.name]: Form,
    [Field.name]: Field,
    [NavBar.name]: NavBar,
    [Button.name]: Button,
    [Popup.name]: Popup,
    [Toast.name]: Toast,
    [Col.name]: Col,
    [Row.name]: Row,
    [Checkbox.name]: Checkbox,
    [CheckboxGroup.name]: CheckboxGroup,
    [TreeSelect.name]: TreeSelect,
    [Notify.name]: Notify,
    [Icon.name]: Icon,
    PickerUnit,
    PickerDate,
    FixedSelect,
    SelectOne,
    MultSelect,
    PickerDateOne,
    FixedSelectOne,
  },
  props: {},
  data() {
    return {
      rowData: {},
      addData: {},
      token: "",
      testId: "",
      MaterialName: "",
      MaterialCode: "",
      OriginName: "", //生产车间名称
      Origin: "", //生产车间编码
      MaterialTypeName: "",
      MaterialType: "",
      ProductSpecification: "", //规格
      PackStandard: "", //包装规格
      BatchID: "",
      ProductDate: "", //生产日期
      EffectDate: "",
      TotalTxt: "", //总量
      count: "",
      unit: "",
      Total: "",
      TestID: "", //请验单编号
      TotalMixingDate: "",
      FirstSample: "",
      FirstSampleArr: [
        { value: "首次", text: "首次" },
        { value: "非首次", text: "非首次" },
      ],
      SampleNumber: "",
      isReadOnly: true,
      PieceTotal: "", //总件数
      SamplePieceStaging: "", //计算公式
      SamplePieceText: "", //计算公式
      SamplePieceValue: "", //取样件数
      SampleRealPiece: "", //实际取样件数
      SampleLocation: "", //取样地点
      SampleLocationArr: [],
      SampleTool: "", //取样工具
      SampleToolArr: [],
      DisinfectDisinfect: "", //是否消毒
      DisinfectDisinfectArr: [
        { value: "False", text: "否" },
        { value: "True", text: "是" },
      ],
      SampleContainer: "", //盛样容器
      SampleContainerArr: [],
      ContainerDisinfect: "", //容器是否消毒
      ContainerDisinfectArr: [
        { value: "False", text: "否" },
        { value: "True", text: "是" },
      ],
      SampleProcess1: "", //取样过程1
      SampleProcess1Arr: [],
      showsample1: false,
      box: "",
      boxUnit: "盒/g",
      boxTime: "",
      SampleProcess2: "", //取样过程2
      SampleProcess2Arr: [],
      showsample2: false,
      ProcessSingleCount: "", //单件取样量约
      ProcessSingleCountUnit: "",
      ProcessSingleCountUnitArr: [
        { value: "g", text: "g" },
        { value: "ml", text: "ml" },
        { value: "粒", text: "粒" },
        { value: "片", text: "片" },
      ],
      ProcessSingleStandard: "", //取样件数
      ProcessSingleStandardUnit: "件",
      ProcessSumCount: "", //总取样量约
      ProcessSumCountUnit: "",
      ProcessSumCountUnitArr: [
        { value: "g", text: "g" },
        { value: "ml", text: "ml" },
        { value: "粒", text: "粒" },
        { value: "片", text: "片" },
      ],
      CleanUser: "", //清洁人
      SampleStart: "", //取样时间
      SampleEnd: "",
      CleanStart: "", //清洁时间
      CleanEnd: "",
      Submission: "", //总检送样
      Physicochemical: "", //理化用
      Microorganism: "", //微生物用
      RetentionSample: "", //留样用
      StorageConditions: "", //样品存储条件
      StorageConditionsArr: [],
      SamplecCode: "", //取样编号
      sampleUserId: "", //取样人
      sampleUserIdArr: [],
      Remark: "", //备注
    };
  },
  watch: {
    FirstSample(val) {
      if (val) {
        this.SampleNumber = "";
        if (val == "首次") {
          this.isReadOnly = true;
        } else {
          this.isReadOnly = false;
        }
      }
    },
    PieceTotal(val) {
      if (val) {
        this.getFormulaData();
      }
    },
    MaterialType(val) {
      if (val) {
        if (
          val == "MaterielType-2-004" ||
          val == "MaterielType-2-003" ||
          val == "MaterielType-2-029"
        ) {
          //成品 中间产品 待包装产品
          this.getSampleLocationData("产品"); // 取样地点
          this.getSampleToolData("产品"); // 取样工具
          this.getSampleContainerData("产品"); // 盛样容器
          this.getSampleProcess1Data("产品"); // 取样过程1
          this.getSampleProcess2Data("产品"); // 取样过程2
          this.getStorageConditionsData("产品"); // 样品存储条件
        } else if (
          val == "MaterielType-2-001" ||
          val == "MaterielType-2-033" ||
          val == "MaterielType-2-020"
        ) {
          //原料 原料药 药用辅料
          this.getSampleLocationData("原料");
          this.getSampleToolData("产品"); // 取样工具;
          this.getSampleContainerData("原料");
          // EnvironmentalConfirmationFun("原料"); // 取样前确认
        } else if (val == "MaterielType-2-035") {
          //中药配方颗粒成品
          this.getSampleLocationData("中药配方颗粒成品");
          this.getStorageConditionsData("中药配方颗粒成品");
        } else if (val == "MaterielType-2-034") {
          //中药配方颗粒中间产品
          this.getSampleLocationData("中药配方颗粒中间产品");
          this.getSampleToolData("中药配方颗粒中间产品");
          this.getSampleContainerData("中药配方颗粒中间产品");
          this.getStorageConditionsData("中药配方颗粒中间产品");
        } else if (
          val == "MaterielType-2-030" ||
          val == "MaterielType-2-031" ||
          val == "MaterielType-2-032"
        ) {
          //内包材 标签 外包材
          this.getSampleLocationData("包材");
          this.getSampleToolData("包材");
          this.getSampleContainerData("包材");
          // EnvironmentalConfirmationFun("包材");
        } else if (val == "MaterielType-2-018" || val == "MaterielType-2-019") {
          //中药材 中药饮片
          this.getSampleLocationData("中药材");
          this.getSampleToolData("中药材");
          this.getSampleContainerData("中药材");
          // EnvironmentalConfirmationFun("中药材");
        }
      }
    },
    SampleProcess1(val) {
      if (val) {
        this.showsample1 = true;
      } else {
        this.showsample1 = false;
      }
    },
    SampleProcess2(val) {
      if (val) {
        this.showsample2 = true;
      } else {
        this.showsample2 = false;
      }
    },
  },
  methods: {
    clickLeft() {
      this.$router.replace({ name: "mySampling" });
    },
    clickRight() {
      this.$refs.subForm.submit();
    },
    async onSubmit(values) {
      var that = this;
      var q = values;
      q["Token"] = this.token;
      q["iautoid"] = this.addData.iautoid;
      q["type"] = this.addData.type;
      if (this.SampleContainer) {
        q["SampleContainer"] = JSON.parse(this.SampleContainer);
      } else {
        q["SampleContainer"] = "";
      }
      if (this.SampleTool) {
        q["SampleTool"] = JSON.parse(this.SampleTool);
      } else {
        q["SampleTool"] = "";
      }
      if (this.sampleUserId) {
        q["sampleUserId"] = JSON.parse(this.sampleUserId);
      } else {
        q["sampleUserId"] = "";
      }
      q["MaterialType"] = this.MaterialType;
      q["Origin"] = this.Origin;
      q["SamplePieceText"] = this.SamplePieceText;
      if (q.box) {
        q["SamplePieceRcord"] = [[{ box: q.box, boxTime: q.boxTime }]];
      }
      if (q.SampleStart) {
        q.SampleStart = q.SampleStart.split(" ")[1];
      }
      if (q.SampleEnd) {
        q.SampleEnd = q.SampleEnd.split(" ")[1];
      }
      saveSampleData(q)
        .then((response) => {
          Notify({ type: "success", message: response.ErrorMsg });
          if (response.ErrorCode == 0) {
            this.$router.replace({ name: "mySampling" });
          }
        })
        .catch(() => {});
    },
    checkAll() {
      this.$refs.checkboxGroup.toggleAll(true);
    },
    toggleAll() {
      this.$refs.checkboxGroup.toggleAll();
    },
    getInfoByTestId() {
      var params = {
        Token: this.token,
        TestID: this.testId,
      };
      GetSampleRecordHeadById(params)
        .then((response) => {
          if (response.ErrorCode == 0) {
            this.rowData = response.Result;
            this.MaterialName = this.rowData.MaterialName;
            this.MaterialCode = this.rowData.MaterialCode;
            this.OriginName = this.rowData.OriginName;
            this.Origin = this.rowData.Origin;
            this.MaterialTypeName = this.rowData.MaterialTypeName;
            this.MaterialType = this.rowData.MaterialType;
            this.ProductSpecification = this.rowData.ProductSpecification;
            this.PackStandard = this.rowData.PackStandard;
            this.TotalTxt = this.rowData.Total + this.rowData.UnitCodeName;
            this.Count = this.rowData.Total;
            this.Unit = this.rowData.UnitCodeName;
            this.Total = this.rowData.Total;
            this.TestID = this.rowData.TestID;
            this.BatchID = this.rowData.BatchID;
            this.ProductDate = this.rowData.ProductDate;
            this.EffectDate = this.rowData.EffectDate;
          }
        })
        .catch(() => {});
    },
    getFormulaData() {
      var valThis = this.PieceTotal;
      if (!valThis) {
        return false;
      }
      if (valThis < 0) {
        Notify({ type: "warnning", message: "不可小于零" });
        return false;
      }
      var ikun = "",
        ikunTxt = "",
        ikunSum = "";
      var mType = this.MaterialType;
      if (
        mType == "MaterielType-2-004" ||
        mType == "MaterielType-2-003" ||
        mType == "MaterielType-2-029" ||
        mType == "MaterielType-2-034" ||
        mType == "MaterielType-2-030" ||
        mType == "MaterielType-2-031" ||
        mType == "MaterielType-2-032" ||
        mType == "MaterielType-2-001" ||
        mType == "MaterielType-2-033" ||
        mType == "MaterielType-2-020"
      ) {
        //成品 中间产品 待包装产品 中药配方颗粒中间产品 内包材 标签 外包材 原料 原料药 药用辅料
        if (valThis <= 3) {
          ikun = valThis;
          ikunTxt = "n≤3,取样件数=n";
          ikunSum = 1;
        } else if (valThis > 3 && valThis <= 300) {
          ikun = Math.ceil(Math.sqrt(valThis)) * 1 + 1;
          ikunTxt = "3<n≤300,取样件数=√n+1";
          ikunSum = 2;
        } else if (valThis > 300) {
          ikunTxt = "n>300,取样件数=(√n/2)+1";
          ikun = Math.ceil(Math.sqrt(valThis / 2)) * 1 + 1;
          ikunSum = 3;
        }
      } else if (
        mType == "MaterielType-2-018" ||
        mType == "MaterielType-2-019"
      ) {
        //中药材 中药饮片
        if (valThis < 5) {
          ikun = valThis;
          ikunTxt = "n<5,逐件取样";
          ikunSum = 1;
          $m(".tradiChinaOne").show();
          $m(".tradiChinaTwo").hide();
        } else if (valThis >= 5 && valThis <= 99) {
          ikun = 5;
          ikunTxt = "5≤n≤99,随机抽签五件";
          ikunSum = 2;
          $m(".tradiChinaOne").show();
          $m(".tradiChinaTwo").hide();
        } else if (valThis >= 100 && valThis <= 1000) {
          ikunTxt = "100≤n≤1000,按5%比例取样";
          ikun = Math.ceil(valThis * 1 * 0.05);
          ikunSum = 3;
          $m(".tradiChinaOne").hide();
          $m(".tradiChinaTwo").show();
        } else if (valThis >= 1000) {
          ikunTxt = "n≥1000,超出部分按1%比例取样";
          ikun = Math.ceil((valThis * 1 - 1000) * 0.01);
          ikunSum = 4;
          $m(".tradiChinaOne").hide();
          $m(".tradiChinaTwo").show();
        } else if (valThis == "贵重药材") {
          ikunTxt = "贵重药材逐件取样";
          ikun = valThis;
          ikunSum = 5;
          $m(".tradiChinaOne").hide();
          $m(".tradiChinaTwo").show();
        }
      }
      this.SamplePieceValue = ikun;
      this.SamplePieceStaging = ikunTxt;
      this.SamplePieceText = ikunSum;
    },
    getSampleLocationData(val) {
      var params = {
        pageModel: { Token: this.token, Search: ["SampleLocation"] },
      };
      getDictionaryTree(params)
        .then((response) => {
          if (response.ErrorCode == 0) {
            var res = response.Result;
            var oldArr = [];
            var newArr = [];
            for (var i = 0; i < res.length; i++) {
              if (val == res[i].no) {
                oldArr = res[i].children;
              }
            }
            if (oldArr && oldArr.length) {
              oldArr.map((item) => {
                newArr.push({
                  value: item.name,
                  text: item.name,
                });
              });
              this.SampleLocationArr = newArr;
            }
          }
        })
        .catch(() => {});
    },
    getSampleToolData(val) {
      var params = {
        pageModel: { Token: this.token, Search: ["SampleTool"] },
      };
      getDictionaryTree(params)
        .then((response) => {
          if (response.ErrorCode == 0) {
            var res = response.Result;
            var oldArr = [];
            var newArr = [];
            for (var i = 0; i < res.length; i++) {
              if (val == res[i].no) {
                oldArr = res[i].children;
              }
            }
            if (oldArr && oldArr.length) {
              oldArr.map((item) => {
                newArr.push({
                  value: item.name,
                  text: item.name,
                });
              });
              this.SampleToolArr = newArr;
            }
          }
        })
        .catch(() => {});
    },
    updataSampleTool(val) {
      this.SampleTool = val;
      console.log(this.SampleTool);
    },
    getSampleContainerData(val) {
      var params = {
        pageModel: { Token: this.token, Search: ["SampleContainer"] },
      };
      getDictionaryTree(params)
        .then((response) => {
          if (response.ErrorCode == 0) {
            var res = response.Result;
            var oldArr = [];
            var newArr = [];
            for (var i = 0; i < res.length; i++) {
              if (val == res[i].no) {
                oldArr = res[i].children;
              }
            }
            if (oldArr && oldArr.length) {
              oldArr.map((item) => {
                newArr.push({
                  value: item.name,
                  text: item.name,
                });
              });
              this.SampleContainerArr = newArr;
            }
          }
        })
        .catch(() => {});
    },
    updataSampleContainer(val) {
      this.SampleContainer = val;
      console.log(this.SampleContainer);
    },
    getSampleProcess1Data(val) {
      var params = {
        pageModel: { Token: this.token, Search: ["SampleProcess1"] },
      };
      getDictionaryTree(params)
        .then((response) => {
          if (response.ErrorCode == 0) {
            var res = response.Result;
            var oldArr = [];
            var newArr = [
              {
                value: "",
                text: "无",
              },
            ];
            for (var i = 0; i < res.length; i++) {
              if (val == res[i].no) {
                oldArr = res[i].children;
              }
            }
            if (oldArr && oldArr.length) {
              oldArr.map((item) => {
                newArr.push({
                  value: item.name,
                  text: item.name,
                });
              });
              this.SampleProcess1Arr = newArr;
            }
          }
        })
        .catch(() => {});
    },
    getSampleProcess2Data(val) {
      var params = {
        pageModel: { Token: this.token, Search: ["SampleProcess2"] },
      };
      getDictionaryTree(params)
        .then((response) => {
          if (response.ErrorCode == 0) {
            var res = response.Result;
            var oldArr = [];
            var newArr = [
              {
                value: "",
                text: "无",
              },
            ];
            for (var i = 0; i < res.length; i++) {
              if (val == res[i].no) {
                oldArr = res[i].children;
              }
            }
            if (oldArr && oldArr.length) {
              oldArr.map((item) => {
                newArr.push({
                  value: item.name,
                  text: item.name,
                });
              });
              this.SampleProcess2Arr = newArr;
            }
          }
        })
        .catch(() => {});
    },
    getStorageConditionsData(val) {
      var params = {
        pageModel: { Token: this.token, Search: ["samplingStorageConditions"] },
      };
      getDictionaryTree(params)
        .then((response) => {
          if (response.ErrorCode == 0) {
            var res = response.Result;
            var oldArr = [];
            var newArr = [];
            for (var i = 0; i < res.length; i++) {
              if (val == res[i].no) {
                oldArr = res[i].children;
              }
            }
            if (oldArr && oldArr.length) {
              oldArr.map((item) => {
                newArr.push({
                  value: item.name,
                  text: item.name,
                });
              });
              this.StorageConditionsArr = newArr;
            }
          }
        })
        .catch(() => {});
    },
    getSampleUserId() {
      var params = {
        Token: this.token,
        searchdepartment: ["QA"],
        Rows: 1000,
        Page: 1,
      };
      GetUserList(params)
        .then((response) => {
          if (response.ErrorCode == 0) {
            var res = response.Result.rows;
            res.map((item) => {
              item.value = item.UserID;
              item.text = item.UserName;
            });
            this.sampleUserIdArr = res;
          }
        })
        .catch(() => {});
    },
    updataSampleUserId(val) {
      this.sampleUserId = val;
      console.log(this.sampleUserId);
    },
  },
  async created() {
    this.token = localStorage.getItem("tokenKey");
    this.addData = JSON.parse(this.$route.params.paramData);
    this.testId = this.addData.testID;
    this.getInfoByTestId();
    this.getSampleUserId();
  },
};
</script>
<style lang="less" scoped>
.form-wapper {
  height: 100%;
  overflow: hidden;
}
.sampleItem {
  height: calc(100% - 1rem);
  overflow: auto;
}
.van-row {
  background: #fff;
}
.van-hairline-unset--top-bottom::after,
.van-hairline--top-bottom::after {
  border-width: 0;
}
.checkItem {
  width: 100%;
  padding: 0 10px;
  margin-top: 20px;
  box-sizing: border-box;
  font-size: 12px;
}
.checkItem > div {
  border: 1px solid #ccc;
}
.itemTit {
  height: 40px;
  background: #49bbef;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  color: #fff;
}
.itemTit button {
  color: #000;
}
.itemContent {
  padding: 10px 10px 0 10px;
  width: 100%;
  box-sizing: border-box;
}
.readonly /deep/.van-field__body {
  background: #ddd;
}
/deep/.van-cell {
  padding: 0.2rem 0.4rem;
}
/deep/.van-field__body {
  border-radius: 2px !important;
  border: 1px solid #ddd;
}
/deep/.van-cell {
  font-size: 0.32rem;
}
</style>